import {useRoute} from 'vue-router'
import {onMounted, ref} from 'vue'
import {getTopCategoryAPI} from '@/apis/category.ts'
import { onBeforeRouteUpdate } from 'vue-router'
export const useCategory =()=>{
    const route = useRoute()
    const categoryData = ref({});
    const getTopCategory = async (id)=>{
        const res = await getTopCategoryAPI(id)
        console.log(res)
        categoryData.value = res.data.result
    }
    onMounted(()=>getTopCategory(route.params.id))
    onBeforeRouteUpdate((to)=>{
        getTopCategory(to.params.id)
    })

    return {
        categoryData
    }
}